package io.renren.modules.aic.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.aic.entity.FaqEntity;
import io.renren.modules.aic.service.FaqService;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 新手问答
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-04-29 11:31:18
 */
@RestController
@RequestMapping("aic/faq")
public class FaqController {
	@Autowired
	private FaqService faqService;

	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("aic:faq:list")
	public R list(@RequestParam Map<String, Object> params) {
		PageUtils page = faqService.queryPage(params);

		return R.ok().put("page", page);
	}

	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("aic:faq:info")
	public R info(@PathVariable("id") Long id) {
		FaqEntity faq = faqService.selectById(id);

		return R.ok().put("faq", faq);
	}

	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("aic:faq:save")
	public R save(@RequestBody FaqEntity faq) {
		// 校验类型
		ValidatorUtils.validateEntity(faq);
		faq.setCreateTime(new Date());
		faqService.insert(faq);
		return R.ok();
	}

	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("aic:faq:update")
	public R update(@RequestBody FaqEntity faq) {
		faqService.updateById(faq);
		return R.ok();
	}

	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("aic:faq:delete")
	public R delete(@RequestBody Long[] ids) {
		faqService.deleteBatchIds(Arrays.asList(ids));
		return R.ok();
	}

}
